package com.dynamic.mybatis.core.metadata;

import com.dynamic.mybatis.core.enums.ReturnType;
import com.dynamic.mybatis.core.toolkit.ReturnTypeHolder;
import com.dynamic.mybatis.core.toolkit.SqlCommandTypeHolder;
import org.apache.ibatis.mapping.SqlCommandType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author xs
 * @Date 2021/3/26 14:29
 */
public class DynamicMappedStatement {

    private String id;//动态sqlID
    private SqlCommandType sqlCommandType;//sql类型
    private ReturnType returnType;
    private String mappedStatement;//映射语句
    private String parameterType;//xml parameterType属性 默认为HashMap
    private Object targetDataSourceKey;//默认数据源key
    private Object[] dynamicDataSourceKeys;//多数据源key
    private Map<String,Object> attributes = new HashMap<>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public SqlCommandType getSqlCommandType() {
        return sqlCommandType;
    }

    public void setSqlCommandType(SqlCommandType sqlCommandType) {
        this.sqlCommandType = sqlCommandType;
    }

    public ReturnType getReturnType() {
        return returnType;
    }

    public void setReturnType(ReturnType returnType) {
        this.returnType = returnType;
    }

    public String getMappedStatement() {
        return mappedStatement;
    }

    public void setMappedStatement(String mappedStatement) {
        this.mappedStatement = mappedStatement;
    }

    public String getParameterType() {
        return parameterType;
    }

    public void setParameterType(String parameterType) {
        this.parameterType = parameterType;
    }

    public Object getTargetDataSourceKey() {
        return targetDataSourceKey;
    }

    public void setTargetDataSourceKey(Object targetDataSourceKey) {
        this.targetDataSourceKey = targetDataSourceKey;
    }

    public Object[] getDynamicDataSourceKeys() {
        return dynamicDataSourceKeys;
    }

    public void setDynamicDataSourceKeys(Object[] dynamicDataSourceKeys) {
        this.dynamicDataSourceKeys = dynamicDataSourceKeys;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, Object> attributes) {
        this.attributes = attributes;
    }

    public static class Builder{
        private   DynamicMappedStatement  parent;

        public Builder() {
            parent = new DynamicMappedStatement();;
        }


        public String getId() {
            return parent.getId();
        }

        public Builder setId(String id) {
            parent.setId(id);
            return this;
        }

        public SqlCommandType getSqlCommandType() {
            return parent.getSqlCommandType();
        }

        public Builder setSqlCommandType(SqlCommandType sqlCommandType) {
            parent.setSqlCommandType(sqlCommandType);
            return this;
        }

        public Builder setSqlCommandType(String sqlCommandType) {
            parent.setSqlCommandType(SqlCommandTypeHolder.getSqlCommandType(sqlCommandType));
            return this;
        }

        public ReturnType getReturnType() {
            return  parent.getReturnType();
        }

        public Builder setReturnType(ReturnType returnType) {
            parent.setReturnType(returnType);
            return this;
        }

        public Builder setReturnType(String returnType) {
            parent.setReturnType(ReturnTypeHolder.getReturnType(returnType));
            return this;
        }


        public String getMappedStatement() {
            return parent.getMappedStatement();
        }

        public Builder setMappedStatement(String mappedStatement) {
            parent.setMappedStatement(mappedStatement);
            return this;
        }

        public String getParameterType() {
            return parent.getParameterType();
        }

        public Builder setParameterType(String parameterType) {
            parent.setParameterType(parameterType);
            return this;
        }

        public Object getTargetDataSourceKey() {
            return parent.getTargetDataSourceKey();
        }

        public Builder setTargetDataSourceKey(Object targetDataSourceKey) {
            parent.setTargetDataSourceKey(targetDataSourceKey);
            return this;
        }

        public Object[] getDynamicDataSourceKeys() {
            return parent.getDynamicDataSourceKeys();
        }

        public Builder setDynamicDataSourceKeys(Object[] dynamicDataSourceKeys) {
            parent.setDynamicDataSourceKeys(dynamicDataSourceKeys);
            return this;
        }

        public Map<String, Object> getAttributes() {
            return parent.getAttributes();
        }

        public Builder setAttributes(Map<String, Object> attributes) {
            parent.getAttributes();
            return this;
        }

        public DynamicMappedStatement builder(){
            return parent;
        }
    }
}